package com.example.device

import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.common.view.view.BaseMvvmActivity
import com.example.device.adapter.DeviceAdapter
import com.example.device.databinding.ActivityDeviceBinding
import com.example.device.vm.DeviceViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/device/DeviceActivity")
class DeviceActivity : BaseMvvmActivity<ActivityDeviceBinding>() {
    override fun getLayoutId(): Int =R.layout.activity_device
    val deviceAdapter=DeviceAdapter()
    private val deviceViewModel:DeviceViewModel by viewModels()
    override fun initView() {
        super.initView()
        mDataBinding.ivBack.setOnClickListener {
            finish()
        }
        mDataBinding.rv.layoutManager=LinearLayoutManager(this)
        mDataBinding.rv.adapter=deviceAdapter
        deviceViewModel.mSuccessLiveData.observe(this){
            deviceAdapter.data.clear()
            deviceAdapter.data.addAll(it.data.reversed())
            deviceAdapter.notifyDataSetChanged()
        }
        deviceViewModel.mErrorLiveData.observe(this){
            ToastUtils.showLong(it)
        }
        //点击添加设备工单
        mDataBinding.addDevice.setOnClickListener {
            ARouter.getInstance().build("/device/DeviceAddActivity").navigation()
        }
    }

    override fun onResume() {
        super.onResume()
        deviceViewModel.getListData()
    }
}